//
//  RankingListViewController.m
//  SlowPlay
//
//  Created by dllo on 15/10/22.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "RankingListViewController.h"
#import "RankingListTotalModel.h"
#import "RankingListDebrisModel.h"
#import "RankingListSongsModel.h"

@interface RankingListViewController ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *rankingListTableView; /**< 排行榜列表*/

@property (nonatomic, strong) NSMutableArray *rankingListArray; /**< 数据源*/

@end


static NSString *const cellIndentifier = @"cellIndentifier";

@implementation RankingListViewController

#pragma mark - 初始化数据源

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.rankingListArray = [NSMutableArray array];
    }
    return self;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    [self createBackButton];
    
    [self createRankingListTableView];
    
    [self getRankingListData];
}

#pragma mark - 自定义导航栏返回按钮
- (void)createBackButton
{
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.backgroundColor = [UIColor clearColor];
    button.frame = CGRectMake(10, 10, 40, 40);
    button.layer.cornerRadius = 10;
    button.clipsToBounds = YES;
    [button setBackgroundImage:[UIImage imageNamed:@"iconfont-fanhuianniu.png"] forState:UIControlStateNormal];
    UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:button];
    [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.leftBarButtonItem = barButton;
}

#pragma mark - 创建tableView
- (void)createRankingListTableView
{
    self.rankingListTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, self.view.frame.size.width, self.view.frame.size.height - 128) style:UITableViewStylePlain];
    self.rankingListTableView.delegate = self;
    self.rankingListTableView.dataSource = self;
    [self.rankingListTableView registerClass:[UITableViewCell class] forCellReuseIdentifier:cellIndentifier];
    [self.view addSubview:self.rankingListTableView];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 10;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIndentifier];
    return cell;
}

- (void)buttonAction:(UIButton *)sender
{
    
    [self dismissViewControllerAnimated:YES completion:^{
        
        
    }];
}


#pragma mark - 获取数据

- (void)getRankingListData
{
    [NetWork netWorkGETRequestWithURLAndNoMub:RankingListNet Paramater:nil ResultBlock:^(id result) {
        NSArray *totalArray = (NSArray *)result;
        for (NSDictionary *dic in totalArray) {
            RankingListTotalModel *model = [[RankingListTotalModel alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            [self.rankingListArray addObject:model];
        }
    }];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
